<template>
  <div>

  </div>
</template>

<script>
  import { ajax } from "@/store/yg/common/utils";

  export default {
    data() {
      return {};
    },

    methods: {
      async check() {
        //获取选中的行
        const ids = this.$store.state.edit.ids;
        const selectedData = this.$store.state.main.selectedData;
        if (selectedData.length < 1) {
          this.$message.error("请至少勾选1条记录！");
          return;
        }
        //校验：草稿和已结束状态不能撤回
        for (let i = 0; i < selectedData.length; i++) {
          let item = selectedData[i];
          if (item.approveStatus == 0) {
            this.$message.error("草稿状态的申请单不能撤回！");
            return;
          }
          if (item.approveStatus == 11) {
            this.$message.error("已结束状态的申请单不能撤回！");
            return;
          }
        }
        //请求后台
        const { code, data, message } = await ajax("revert", {
          ids: ids
        });
        if (code !== 200) {
          if (message) {
            this.$message.error(message);
          } else {
            this.$message.error("服务器异常");
          }
          return;
        }
        this.$message({
          type: "success",
          message: "撤回成功！"
        });
      }
    },

    mounted() {
      this.check();
    }
  };
</script>


<style>

</style>
